﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using clf.weighing.entity;
using MyHelper;

namespace weighing
{
    /// <summary>
    /// 自定义磅单
    /// </summary>


    public class SysCustomizeBillVo : BaseVo
    {
        #region Constract
        public CustomizeBill mCustomizeBill;
        public SysCustomizeBillVo(CustomizeBill customizeBill)
        {
            mCustomizeBill = customizeBill;
        }
        #endregion



        public Int64 Id
        {
            get
            {
                return mCustomizeBill.id;
            }
            set
            {
                mCustomizeBill.id = value;
                OnPropertyChanged(this, nameof(Id));
            }
        }

        /// <summary>
        /// 注释:磅单名称
        /// 可空:YES
        /// </summary>

        public String Name
        {
            get
            {
                return mCustomizeBill.name;
            }
            set
            {
                mCustomizeBill.name = value;
                OnPropertyChanged(this, nameof(Name));
            }
        }

        /// <summary>
        /// 注释:类型 (0:其它，1:采购,2:销售,3:内部倒运,4:外来过磅 ,100:未知)
        /// 可空:YES
        /// 默认值:0
        /// </summary>

        public Int32? Type
        {
            get
            {
                return mCustomizeBill.type;
            }
            set
            {
                mCustomizeBill.type = value;
                OnPropertyChanged(this, nameof(Type));
            }
        }

        /// <summary>
        /// 注释:自定义(XAML)内容
        /// 可空:YES
        /// </summary>

        public String Content
        {
            get
            {
                return mCustomizeBill.content;
            }
            set
            {
                mCustomizeBill.content = value;
                OnPropertyChanged(this, nameof(Content));
            }
        }

        /// <summary>
        /// 注释:所属公司ID
        /// 可空:NO
        /// 默认值:0
        /// </summary>
        public Int64 CompanyId
        {
            get
            {
                return mCustomizeBill.companyId;
            }
            set
            {
                mCustomizeBill.companyId = value;
                OnPropertyChanged(this, nameof(CompanyId));
            }
        }

        /// <summary>
        /// 注释:是否使用（0否:,1:是）
        /// 可空:YES
        /// 默认值:0
        /// </summary>

        public Boolean? IsUsed
        {
            get
            {
                return mCustomizeBill.isUsed;
            }
            set
            {
                mCustomizeBill.isUsed = value;
                OnPropertyChanged(this, nameof(IsUsed));
            }
        }

        public DateTime? AddTime
        {
            get
            {
                return mCustomizeBill.addTime;
            }
            set
            {
                mCustomizeBill.addTime = value;
                OnPropertyChanged(this, nameof(AddTime));
            }
        }


        public double? PrintWidth
        {
            get { return mCustomizeBill.printWidth; }
            set { mCustomizeBill.printWidth =value; OnPropertyChanged(this, nameof(PrintWidth)); }
        }

        public double? PrintHeight
        {
            get { return mCustomizeBill.printHeight; }
            set { mCustomizeBill.printHeight = value; 
                OnPropertyChanged(this, nameof(PrintHeight)); }
        }
        public double? LeftDistance
        {
            get { return mCustomizeBill.leftDistance; }
            set
            {
                mCustomizeBill.leftDistance = value;
                OnPropertyChanged(this, nameof(LeftDistance));
            }
        }
        public double? TopDistance
        {
            get { return mCustomizeBill.topDistance; }
            set
            {
                mCustomizeBill.topDistance = value;
                OnPropertyChanged(this, nameof(TopDistance));
            }
        }

        public DateTime? UpdateTime
        {
            get
            {
                return mCustomizeBill.updateTime;
            }
            set
            {
                mCustomizeBill.addTime = value;
                OnPropertyChanged(this, nameof(UpdateTime));
            }
        }

        #region Qr Rule

        /// <summary>
        /// 二维码解析规则
        ///  1 不包含 | 
        ///     1.1 内容为 number ,以磅单编号为内容生成二维码
        ///     1.2 内容为 url ,以磅单图片的访问路径为内容生成二维码
        ///     
        ///  2. 包含 |
        ///   2.1 每一个 | 分开的内容为数据库中的值
        ///   2.1 包含中文的字段注意需要转码（类型为 String or String?）
        /// </summary>
        //public String QrRule
        //{
        //    get
        //    {
        //        return mCustomizeBill.qrRule;
        //    }
        //    set
        //    {
        //        mCustomizeBill.qrRule = value;
        //        OnPropertyChanged(this, nameof(QrRule));
        //    }
        //}
        #endregion


        #region new  Qr Rule

        /// <summary>
        /// 二维码解析规则
        ///  1 不包含 | 
        ///     1.1 内容为 number ,以磅单编号为内容生成二维码
        ///     1.2 内容为 url ,以磅单图片的访问路径为内容生成二维码
        ///     
        ///  2. 包含 |
        ///   2.1 每一个 | 分开的内容为数据库中的值
        ///   2.1 包含中文的字段注意需要转码（类型为 String or String?）
        /// </summary>
        public QrContentVo QrContentVo
        {
            get
            {
                if (string.IsNullOrEmpty(mCustomizeBill.qrRule))
                {
                    mCustomizeBill.qrRule = "{}";
                }
                if (!(mCustomizeBill.qrRule.StartsWith("{") && mCustomizeBill.qrRule.EndsWith("}")))
                {
                    mCustomizeBill.qrRule = "{}";
                }
                return JsonHelper.JsonToObject<QrContentVo>(mCustomizeBill.qrRule);
            }
            set
            {
                var json = JsonHelper.ObjectToJson(value);
                mCustomizeBill.qrRule = json;
                OnPropertyChanged(this, nameof(QrContentVo));
            }
        }
        #endregion

        #region TEXT
        public String IsUsedText
        {
            get
            {
                return mCustomizeBill.isUsed == true ?"使用":"未使用";
            }         
        }

        public String UseBtnText
        {
            get
            {
                return mCustomizeBill.isUsed == false ? "使用" : "不使用";
            }
        }

        public String TypeText
        {
            get
            {
                string res = "未知";

                switch (mCustomizeBill.type)
                {
                    case (int)WeightingBillType.Buy:
                        res = "采购磅单";
                        break;
                    case (int)WeightingBillType.Sale:
                        res = "销售磅单";
                        break;
                    case (int)WeightingBillType.Self:
                        res = "内部倒运磅单";
                        break;
                    case (int)WeightingBillType.Foreign:
                        res = "外来过磅磅单";
                        break;
                    case (int)WeightingBillType.Mixture:
                        res = "混合过磅磅单";
                        break;
                    case (int)WeightingBillType.ExitSlip:
                        res = "出门条";
                        break;
                }
                return res;
            }
        }

        #endregion



    }
}
